package com.gykfbxxh.imovie.view.main.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.gykfbxxh.imovie.R;
import com.gykfbxxh.imovie.adapter.MyIndicatorViewPagerAdapter;
import com.gykfbxxh.imovie.base.BaseFragment;
import com.gykfbxxh.imovie.bean.config.ChannelItem;
import com.gykfbxxh.imovie.custom.view.vpindicator.ColorBar;
import com.gykfbxxh.imovie.custom.view.vpindicator.IndicatorViewPager;
import com.gykfbxxh.imovie.custom.view.vpindicator.OnTransitionTextListener;
import com.gykfbxxh.imovie.custom.view.vpindicator.ScrollIndicatorView;
import com.gykfbxxh.imovie.manager.AppChannelManager;
import com.gykfbxxh.imovie.view.set.SearchActivity;

import java.util.List;

/**
 * Created by xuxinghai
 * On 2017/8/25
 * 片库fragment
 */

public class FilmLibraryFragment extends BaseFragment  {
    private Activity mActivity;
    private ViewGroup mContentView;//根布局
    private IndicatorViewPager indicatorViewPager;
    private List<ChannelItem> userChannelList;
    private LinearLayout ll_rightview;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onAttach(Activity activity) {
        mActivity = activity;
        super.onAttach(activity);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mContentView == null) {
            mContentView = (ViewGroup) inflater.inflate(
                    R.layout.fragment_film_library, null);
            initView();
        }


        return mContentView;
    }

    /**
     * 初始化layout控件
     */
    private void initView() {
        ViewPager viewPager = (ViewPager) mContentView.findViewById(R.id.moretab_viewPager);
        ScrollIndicatorView scrollIndicatorView = (ScrollIndicatorView) mContentView.findViewById(R.id.moretab_indicator);
        ll_rightview = (LinearLayout) mContentView.findViewById(R.id.ll_rightview);
        ll_rightview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mActivity, SearchActivity.class));
            }
        });
        float unSelectSize = 12;
        float selectSize = unSelectSize * 1.3f;
//        scrollIndicatorView.setOnTransitionListener(new OnTransitionTextListener().setColor(0xFF2196F3, Color.GRAY).setSize(selectSize, unSelectSize));
        scrollIndicatorView.setOnTransitionListener(new OnTransitionTextListener().setColor(0xFF161616, 0xFF606060).setSize(selectSize, selectSize));

        scrollIndicatorView.setScrollBar(new ColorBar(mActivity, 0xFFF9D13F, 4));

        userChannelList = AppChannelManager.getInstance().getUserChannel();
        viewPager.setOffscreenPageLimit(userChannelList.size());
        indicatorViewPager = new IndicatorViewPager(scrollIndicatorView, viewPager);
        indicatorViewPager.setAdapter(new MyIndicatorViewPagerAdapter(((FragmentActivity)mActivity).getSupportFragmentManager(),mActivity,userChannelList));
        indicatorViewPager.notifyDataSetChanged();
    }





    /* 刷新当前页面数据 */
    public void flushCurrentPage() {
//        if (fragments == null || mViewPager == null) {
//            return;
//        }
//        FilmsFragment currentFragment = (FilmsFragment) fragments.get(mViewPager.getCurrentItem());
//        if (currentFragment != null) {
//            currentFragment.flushData();
//        }

    }


}
